package Framework
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.getTimer;

	public class FPS
	{
		private var numFrames:Number = 0; 
		private var interval:Number = 10 
		private var startTime:Number; 
		private var _container:Sprite
		[Bindable]
		public var current:Number=0
		public function FPS()
		{
		}
		public function attach(container:Sprite):void{
			_container = container;
			_container.addEventListener(Event.ENTER_FRAME,onFrame);
			startTime = getTimer();
		}
		public function detach():void{
			_container.removeEventListener(Event.ENTER_FRAME,onFrame);
		}
		private function onFrame(e:Event):void{
			if (++numFrames == interval) { 
				var now:Number = getTimer(); 
				var elapsedSeconds:Number = (now - startTime) / 1000; 
				current = numFrames / elapsedSeconds;         
				startTime = now; 
				numFrames = 0; 
			} 			
		}
	}
}